
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       rcprotocol_sbus.h
  * @author     baiyang
  * @date       2022-6-11
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include "rcprotocol_backend.h"

#include "SoftSerial.h"
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/
typedef struct rcprotocol_sbus* rcprotocol_sbus_t;

struct rcprotocol_sbus {
    struct rcprotocol_backend backend;

    bool inverted;
    struct soft_serial ss;
    uint32_t saved_width;

    struct {
        uint8_t buf[25];
        uint8_t ofs;
        uint32_t last_byte_us;
    } byte_input;
};

/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void rcprotocol_sbus_ctor(rcprotocol_sbus_t sbus, bool _inverted, uint32_t configured_baud);
rcprotocol_backend_t rcprotocol_sbus_probe(bool _inverted, uint32_t configured_baud);
/*------------------------------------test------------------------------------*/

#ifdef __cplusplus
}
#endif



